﻿using System.Windows;
using System;

namespace ZOIL.Framework.Presentation
{
    /// <summary>
    /// Zoom Modifier for corners.
    /// </summary>
    public class CornerRadiusModifier : ZoomModifier
    {
        #region dp

        /// <summary>
        /// 
        /// </summary>
        public static readonly DependencyProperty ModifierProperty = DependencyProperty.Register("Modifier", typeof(double), typeof(CornerRadiusModifier), new PropertyMetadata(0.0));

        /// <summary>
        /// 
        /// </summary>
        public double Modifier
        {
            get { return (double)this.GetValue(ModifierProperty); }
            set { this.SetValue(ModifierProperty, value); }
        }

        #endregion

        #region overrides

        /// <summary>
        /// 
        /// </summary>
        /// <param name="source"></param>
        /// <param name="zoom"></param>
        public override void Update(DependencyObject source, double zoom)
        {
            if (source == null)
            {
                throw new ArgumentNullException("source");
            }
            
            base.Update(source, zoom);

            double modifier = Interpolate(zoom, this.Modifier);
            CornerRadius originalRadius = (CornerRadius)OriginalValue;
            CornerRadius newRadius = new CornerRadius(
                originalRadius.TopLeft * modifier,
                originalRadius.TopRight * modifier,
                originalRadius.BottomRight * modifier,
                originalRadius.BottomLeft * modifier);

            source.SetValue(this.Property, newRadius);
        }

        #endregion
    }
}
